package cn.tedu.dimanage.donation.webapi.controller;

import cn.tedu.dimanage.common.web.JsonResult;
import cn.tedu.dimanage.donation.service.IDonationService;
import cn.tedu.dimanage.pojo.dto.DonationAddNewDTO;
import cn.tedu.dimanage.pojo.dto.DonationCheckDTO;
import cn.tedu.dimanage.pojo.dto.DonationUpdateDTO;
import cn.tedu.dimanage.pojo.vo.DonationDetailsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Classname: DonationController
 * @Author: bromide
 * @CreateTime: 2022/6/27--20:28
 * @Version: V1.0
 * @Description:
 */
@RestController
@RequestMapping(value = "/donation",produces = "application/json;charset=utf-8")
public class DonationController {
    @Autowired
    private IDonationService donationService;

    @PostMapping("/add-new")
    public JsonResult<Void> addDonation(DonationAddNewDTO donationAddNewDTO){
        donationService.addDonation(donationAddNewDTO);
        return JsonResult.ok();
    }

    @GetMapping("/selectList")
    public JsonResult<List<DonationDetailsVO>> selectDonationList(String keyword){
        List<DonationDetailsVO> donationDetailsVOS = donationService.selectDonationList(keyword);
        return JsonResult.ok(donationDetailsVOS);
    }

    @GetMapping("/selectListByUserId")
    public JsonResult<List<DonationDetailsVO>> selectDonationListByUserId(Long userId){
        List<DonationDetailsVO> donationDetailsVOS = donationService.selectDonationListByUserId(userId);
        return JsonResult.ok(donationDetailsVOS);
    }

    @GetMapping("/selectIn")
    public JsonResult<List<DonationDetailsVO>> selectDonationIn(String keyword){
        List<DonationDetailsVO> donationDetailsVOS = donationService.selectDonationIn(keyword);
        return JsonResult.ok(donationDetailsVOS);
    }

    @RequestMapping("/update-admin")
    public JsonResult<Void> updateDonationByAdmin(DonationCheckDTO donationCheckDTO){
        donationService.updateDonationByAdmin(donationCheckDTO);
        return JsonResult.ok();
    }

    @RequestMapping("/update-user")
    public JsonResult<Void> updateDonationByUser(DonationUpdateDTO donationUpdateDTO){
        donationService.updateDonationByUser(donationUpdateDTO);
        return JsonResult.ok();
    }

    @RequestMapping("/deleteById")
    public JsonResult<Void> deleteDonationById(Long id){
        donationService.deleteDonationById(id);
        return JsonResult.ok();
    }

}
